
<!DOCTYPE html>
<html xmlns:th="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <title>分类维护</title>
    <link href="/static/devtools30/layui/css/layui.css" rel="stylesheet" />
    <link href="/static/devtools30/css/devindexbase.css" rel="stylesheet" />
    <script src="/static/devtools30/js/jquery-1.11.2.min.js" type="text/javascript"></script>
    <script src="/static/devtools30/js/devtoolCommon.js" type="text/javascript"></script>
    <script src="/static/devtools30/layui/layui.all.js" type="text/javascript"></script>
    <style>
        /*按钮大小*/

        .layui-btn {
            height: 26px;
            line-height: 26px;
            font-size: 11px;
        }
        /*顶部容器*/
        .topwrap {
            height: 32px;
            line-height: 32px;
            border: 1px solid #F7F7F7;
            padding: 0 5px;
            margin: 0 2px;
        }
        /*按钮组边框*/
        .layui-btn-group .layui-btn {
            border-left: 1px solid rgba(255, 255, 255, .5)!important;
        }
        .layui-btn-group .layui-btn-primary:first-child {
            border-left: 1px solid #c9c9c9!important;
        }

        /*table表格边距*/
        .layui-table,
        .layui-table-view {
            margin: 0;
        }
    </style>

</head>
<body>
<div>
    <div class="flex  flex-align-center flex-jusity-betreen topwrap backgroundf">
        <div style="color: #ccc"> 注：点击单元格可以修改数据</div>
        <div class="layui-btn-group btnwrap">
            <button type="button" class="layui-btn layui-btn-primary layui-btn-sm" onclick='saveAll()'>数据保存</button>

        </div>
    </div>
    <div style="padding: 2px;width: 100%;background: #F7F7F7;">
        <div class="backgroundf">
            <table id="mygrid" lay-filter="mygrid"></table>
        </div>
    </div>
</div>
</body>
<script>
    var height = dlCommon.getWinHeight();
    var width=dlCommon.getWinWidth();
    var formId = '[(${formId})]';

    $(function(){
        initGrid();

        initEvent();
        loadData();
    })

    function loadData(){

    }
    function initGrid(){
        layui.table.render({
            elem: '#mygrid',
            height: height-36,

            data:[(${fieldEntities})],
            size: 'sm', //小尺寸的表格
            loading:false,
            page: false, //开启分页
            limit: Number.MAX_VALUE,
            cols: [
                [ //表头
                    { field: 'xh', title: '序号', width: 80, fixed: 'left' },
                    { field: 'fieldName', title: '中文名称', sort: true, width: 100,edit:"text" },
                    { field: 'fieldCode', title: '字段代码', sort: true, width: 100,edit:"text" },
                    { field: 'pkey', title: '主键', sort: true, width: 100,edit:"text",templet: function(d){
                            var str="否";
                            if(d.pkey==1){
                                str="是"
                            }
                            return str;
                        } },
                    { field: 'fieldType', title: '字段类型', sort: true, width: 100,edit:"text" },
                    { field: 'typeLength', title: '字段长度', sort: true, width: 100,edit:"text" },
                    { field: 'typeZeroLength', title: '小数位数', sort: true, width: 100,edit:"text" },
                    { field: 'bz', title: '备注', width: 200,edit:"text" },
                    { field: 'opera', title: '操作', width: 120,templet: function(d){
                            var str="";

                            // str += '<button type="button" onclick="editField(\''+d.id+'\')" class="layui-btn layui-btn-normal layui-btn-xs layui_edit_btn">修改</button>';
                            str += '<button type="button" onclick="delField(\''+d.LAY_TABLE_INDEX+'\')" class="layui-btn layui-btn-danger layui-btn-xs layui_edit_btn">删除</button>';

                            return str;
                        }
                    }
                ]
            ]
        });
    }
    function initEvent(){
        //增删改点击方法

        dlCommon.layerTableOn('mygrid', function(obj){

        });
        layui.table.on('edit(mygrid)', function(obj){
            var value = obj.value //得到修改后的值
                ,data = obj.data //得到所在行所有键值
                ,field = obj.field; //得到字段
            data[field]=value;
            obj.update(data)
        });
    }
    function delField(index) {

        dlCommon.layerConfirm("是否确定删除？",function(){
            var data= layui.table.cache['mygrid'];
            data.splice(index, 1)
            layui.table.reload("mygrid", {
                data: data
            })
        })

    }
    function saveAll(){
       var data= layui.table.cache['mygrid'];
       if(!data||data.length==0){
           dlCommon.layerInfo("没有数据无法提交");
           return;
       }
        dlCommon.ajaxJsonStr('/DevtModelMetadataFieldController/saveAll?fromId='+formId,data,function(dataremot) {

            if (dataremot.success == false) {
                dlCommon.layerError(dataremot.msg);
            }else{
                parent.getFieldList();
                dlCommon.layerSuccess("成功", function () {
                    //关闭窗体
                    dlCommon.closeParentLayer();
                });
            }
        },true)

    }
</script>
</html>
